package com.lz.timer.an.config.simple;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import com.dangdang.ddframe.job.api.ElasticJob;
import com.dangdang.ddframe.job.lite.api.JobScheduler;
import com.lz.timer.an.config.BaseJobConfig;
import com.lz.timer.an.config.BaseJobConfigBean;
import com.lz.timer.an.ddjobs.simple.StatisticalAuditFailureJob;
import com.lz.timer.an.ddjobs.simple.StatisticalPlanInOperationJob;

/**
 * @author rench
 * @Description: 推广计划投放中 作业配置
 */
@Configuration
public class StatisticalPlanInOperationJobConfig extends BaseJobConfig {

    /**
     * job bean 名称
     */
    private static final String JOB_BEAN_NAME = "statisticalPlanInOperation";
    private static final String ELASTIC_JOB_BEAN_NAME = JOB_BEAN_NAME + "ElasticJob";
    private static final String JOB_CONFIG_BEAN_NAME = JOB_BEAN_NAME + "BeanConfig";
    private static final String JOB_CONFIG_BEAN_PREFIX = "job." + JOB_BEAN_NAME;
    private static final String JOB_SCHEDULER_BEAN_NAME = JOB_BEAN_NAME + "Scheduler";

    /**
     * 注入ElasticJob bean
     *
     * @return
     */
    @Bean(ELASTIC_JOB_BEAN_NAME)
    public ElasticJob elasticJob() {
        // 返回对应的ElasticJob
        return new StatisticalPlanInOperationJob();
    }

    /**
     * @author liuzhangcheng
     * @Description: job配置
     */
    @Component(JOB_CONFIG_BEAN_NAME)
    @ConfigurationProperties(prefix = JOB_CONFIG_BEAN_PREFIX)
    private static class JobConfigBean extends BaseJobConfigBean {

    }

    /**
     * 作业调度器
     *
     * @param elasticJob
     * @param jobConfigBean
     * @return
     */
    @Bean(name = JOB_SCHEDULER_BEAN_NAME, initMethod = "init")
    public JobScheduler jobScheduler(@Qualifier(ELASTIC_JOB_BEAN_NAME) final ElasticJob elasticJob,
                                     @Qualifier(JOB_CONFIG_BEAN_NAME) final BaseJobConfigBean jobConfigBean) {

        return super.springJobScheduler(elasticJob, jobConfigBean);
    }

}